package com.fsnbigdata.repository;
import io.springlets.data.jpa.repository.support.QueryDslRepositorySupportExt;
import org.springframework.roo.addon.layers.repository.jpa.annotations.RooJpaRepositoryCustomImpl;
import com.fsnbigdata.domain.ProductImage;
import com.fsnbigdata.domain.Product;
import com.fsnbigdata.domain.QProductImage;
import com.querydsl.core.types.Path;
import com.querydsl.jpa.JPQLQuery;
import io.springlets.data.domain.GlobalSearch;
import io.springlets.data.jpa.repository.support.QueryDslRepositorySupportExt.AttributeMappingBuilder;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

/**
 * = ProductImageRepositoryImpl
 *
 * TODO Auto-generated class documentation
 *
 */
@RooJpaRepositoryCustomImpl(repository = ProductImageRepositoryCustom.class)
@Transactional(readOnly = true)
public class ProductImageRepositoryImpl extends QueryDslRepositorySupportExt<ProductImage> implements ProductImageRepositoryCustom {

    /**
     * TODO Auto-generated constructor documentation
     */
    ProductImageRepositoryImpl() {
        super(ProductImage.class);
    }

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String LOCATION = "location";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String CODE = "code";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String CREATE_DATE = "createDate";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String DESCRIPTION = "description";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String PRODUCT = "product";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String AUTHOR = "author";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String URL = "url";

    /**
     * TODO Auto-generated method documentation
     *
     * @param product
     * @param globalSearch
     * @param pageable
     * @return Page
     */
    public Page<ProductImage> findByProduct(Product product, GlobalSearch globalSearch, Pageable pageable) {
        QProductImage productImage = QProductImage.productImage;
        JPQLQuery<ProductImage> query = from(productImage);
        Assert.notNull(product, "product is required");
        query.where(productImage.product.eq(product));
        Path<?>[] paths = new Path<?>[] { productImage.product, productImage.code, productImage.description, productImage.location, productImage.author, productImage.url, productImage.createDate };
        applyGlobalSearch(globalSearch, query, paths);
        AttributeMappingBuilder mapping = buildMapper().map(PRODUCT, productImage.product).map(CODE, productImage.code).map(DESCRIPTION, productImage.description).map(LOCATION, productImage.location).map(AUTHOR, productImage.author).map(URL, productImage.url).map(CREATE_DATE, productImage.createDate);
        applyPagination(pageable, query, mapping);
        applyOrderById(query);
        return loadPage(query, pageable, productImage);
    }
}
